package com.mlh.annotation_test;

import com.mlh.dto.AnnotationTest1RequestDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author 缪林辉
 * @date 2024/12/11 10:14
 * @DESCRIPTION
 */
@Controller
@RequestMapping("/annotation")
public class AnnotationTest1 {

    // post情况下
    //@RequestParam  可以接收以下数据
    //?param1=100
    // body content-type=form-data或者application/x-www-form-urlencoded编码的内容
    @RequestMapping(value = "/test1", method = RequestMethod.POST)
    public String test1(@RequestParam int param1) {
        System.out.println(param1);
        return "success";
    }

    // get情况下
    //@RequestParam  只能接受?param1=100
    @RequestMapping(value = "/test3", method = RequestMethod.GET)
    public String test3(@RequestParam int param1) {
        System.out.println(param1);
        return "success";
    }

    //@RequestBody只能接受POST content-Type=application/json的数据
    @RequestMapping(value = "/test2", method = RequestMethod.POST)
    public String test2(@RequestBody AnnotationTest1RequestDTO requestDTO) {
        System.out.println(requestDTO.param1);
        return "success";
    }

    // 参数不写任何注解时，应该是默认给了@RequestParam注解
    @RequestMapping(value = "/test5", method = RequestMethod.POST)
    public String test5(int param1) {
        System.out.println(param1);
        return "success";
    }
}
